{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "print 1 == 0\n",
    "print 1 == 1\n",
    "print 1 != 0\n",
    "print 5 >= 5\n",
    "print 5 >= 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "print 2 > 1 and 3 > 2\n",
    "print 2 > 1 and 3 < 2 \n",
    "print 2 > 1 or 3 < 2\n",
    "print 2 < 1 and 3 < 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print (3 > 2 or 1 < 3) and (1!=3 and 4>3) and not ( 3 < 2 or 1 < 3 and (1!=3 and 4>3))\n",
    "print 3 > 2 or 1 < 3 and (1!=3 and 4>3) and not ( 3 < 2 or 1 < 3 and (1!=3 and 4>3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block (<ipython-input-5-91506eaa57cd>, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-5-91506eaa57cd>\"\u001b[0;36m, line \u001b[0;32m5\u001b[0m\n\u001b[0;31m    elif statement2:\u001b[0m\n\u001b[0m       ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n"
     ]
    }
   ],
   "source": [
    "if statement1:\n",
    "    # if the statement1 is true, execute the code here.\n",
    "    # code.....\n",
    "    # code.....\n",
    "elif statement2:\n",
    "    # if the statement 1 is false, skip the codes above to this part.\n",
    "    # code......\n",
    "    # code......\n",
    "else:\n",
    "    # if none of the above statements is True, skip to this part\n",
    "    # code......"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i==0 is True\n"
     ]
    }
   ],
   "source": [
    "i = 0\n",
    "if i == 0:\n",
    "    print 'i==0 is True'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "q is false\n"
     ]
    }
   ],
   "source": [
    "p = 1 > 0\n",
    "q = 2 > 3\n",
    "if p and q:\n",
    "    print 'p and q is true'\n",
    "elif p and not q:\n",
    "    print 'q is false'\n",
    "elif q and not p:\n",
    "    print 'p is false'\n",
    "else:\n",
    "    print 'None of p and q is true'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "i = 0\n",
    "while i < 5:\n",
    "    print i\n",
    "    i += 1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3,4,5]:\n",
    "    print i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['AAPL', 'GOOG', 'IBM', 'FB', 'F', 'V', 'G', 'GE']\n"
     ]
    }
   ],
   "source": [
    "stocks = ['AAPL','GOOG','IBM','FB','F','V', 'G', 'GE']\n",
    "selected = ['AAPL','IBM']\n",
    "new_list = []\n",
    "for i in stocks:\n",
    "    if i not in selected:\n",
    "        new_list.append(i)\n",
    "print stocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AAPL\n",
      "GOOG\n",
      "IBM\n",
      "FB\n"
     ]
    }
   ],
   "source": [
    "stocks = ['AAPL','GOOG','IBM','FB','F','V', 'G', 'GE']\n",
    "for i in stocks:\n",
    "    print i\n",
    "    if i == 'FB':\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AAPL\n",
      "GOOG\n",
      "IBM\n",
      "F\n",
      "V\n",
      "G\n",
      "GE\n"
     ]
    }
   ],
   "source": [
    "stocks = ['AAPL','GOOG','IBM','FB','F','V', 'G', 'GE']\n",
    "for i in stocks:\n",
    "    if i == 'FB':\n",
    "        continue\n",
    "    print i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 9, 16, 25]\n"
     ]
    }
   ],
   "source": [
    "squares = []\n",
    "for i in [1,2,3,4,5]:\n",
    "    squares.append(i**2)\n",
    "print squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 9, 16, 25]\n"
     ]
    }
   ],
   "source": [
    "list = [1,2,3,4,5]\n",
    "squares = [x**2 for x in list]\n",
    "print squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['AAPL', 'IBM']\n"
     ]
    }
   ],
   "source": [
    "stocks = ['AAPL','GOOG','IBM','FB','F','V', 'G', 'GE']\n",
    "selected = ['AAPL','IBM']\n",
    "new_list = [x for x in stocks if x in selected]\n",
    "print new_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]\n",
      "['AAPL vs F', 'AAPL vs V', 'AAPL vs G', 'AAPL vs GE', 'GOOG vs F', 'GOOG vs V', 'GOOG vs G', 'GOOG vs GE', 'IBM vs F', 'IBM vs V', 'IBM vs G', 'IBM vs GE', 'FB vs F', 'FB vs V', 'FB vs G', 'FB vs GE']\n"
     ]
    }
   ],
   "source": [
    "print [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]\n",
    "print [str(x)+' vs '+str(y) for x in ['AAPL','GOOG','IBM','FB'] for y in ['F','V','G','GE'] if x!=y]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
